package com.lottery.ruok.lottrey.chat.event.manager;

import utils.AESUtils;

/**
 * 加解密管理
 */
public class SecretManager {
    private static SecretManager secretManager;
    private final AESUtils aesUtils;

    public static synchronized SecretManager getInstance() {
        if (secretManager == null) {
            secretManager = new SecretManager();
        }
        return secretManager;
    }

    public SecretManager() {
        aesUtils = new AESUtils(AESUtils.KEY);
    }

    /**
     * 加密
     */
    public String encode(String text) throws Exception {
        String result = null;
        if (aesUtils != null) {
            result = aesUtils.encryptData(text);
        }
        return result;
    }

    /**
     * 解密
     *
     * @param text
     * @return
     * @throws Exception
     */
    public String decode(String text) throws Exception {
        String result = null;
        if (aesUtils != null) {
            result = aesUtils.decryptData(text);
        }
        return result;
    }


}
